<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //set 用法

        //const s = new Set([1, 2, 3, 4, 4])
        //输出结果为1234，证明set里的元素不重复（去重功能）
        //console.log(s);


        //console.log(typeof s) 
        //返回object

        // let set = new Set([1, 2, 3, 4])
        // let res = set instanceof Set
        // let resSet = Object.prototype.toString.call(set)
        // console.log(res); //结果为true证明是set数据类型
        // console.log(resSet); //结果是[object set]


        //set转化数组
        // const set = new Set([1, 2, 3, 4, 4]);
        // console.log([...set]);
        // console.log(Array.from(set));

        // let set = new Set();
        // let a = 5;
        // let b = '5';
        // set.add(a);set.add(b);
        // console.log(Array.from(set));

        // let set = new Set();
        //    let a = NaN;
        //    let b = NaN;
        //    set.add(a);set.add(b);
        //    console.log(Array.from(set));    //结果返回NaN
        //    console.log(Array.from(set));    //结果不返回

        //set的size属性
        // let set = new Set();
        // s.add(1).add(2).add(2);
        // s.set

        // let set = new Set([1, 4, 9]);
        // set.forEach((value, key) => console.log(key + ': ' + value))
        //输出结果key 和 value都是1、4、9


        //set中的交集和并集
        let arr1 =[1, 2 ,3]
        let arr2 =[4, 3 ,2]
        let a = new Set(arr1);
        let b = new Set(arr2);

        console.log([...a])
        //使用filter查看交集
        let intersect = new Set([...a].filter(x => b.has(x)));
        console.log(intersect)
        //输出结果为 set{2,3} 交集为2,3

        //查看差集
        // let intersect = new Set([...a].filter(x => b.has(x)));


    </script>
</body>
</html>